using UnityEngine;
using System.Collections;

public class Rectangle
{
	public int Height;
    public int Width;
    public int X;
    public int Y;
	
	public Rectangle(int x, int y, int width, int height)
	{
		Height = height;
		Width = width;
		X = x;
		Y = y;
	}
	
	public Rectangle(float x, float y, float width, float height)
	{
		Height = (int)height;
		Width = (int)width;
		X = (int)x;
		Y = (int)y;
	}	
	
	public int Bottom { get {return Y - Height / 2;} }
	public int Left { get {return X - Width / 2;} }
	public int Right { get {return X + Width / 2;} }
	public int Top { get {return Y + Height / 2;} }
	
	public Vector2 Center { get { return new Vector2(X, Y); } }
	
	public Vector2 TopLeftPt { get {return new Vector2(Left, Top); } }
	public Vector2 TopRightPt { get {return new Vector2(Right, Top); } }
	public Vector2 BottomLeftPt { get {return new Vector2(Left, Bottom); } }
	public Vector2 BottomRightPt { get {return new Vector2(Right, Bottom); } }
	
	public Segment LeftBorder { get {return new Segment(TopLeftPt, BottomLeftPt); } }
	public Segment TopBorder { get {return new Segment(TopLeftPt, TopRightPt); } }
	public Segment BottomBorder { get {return new Segment(BottomLeftPt, BottomRightPt); } }
	public Segment RightBorder { get {return new Segment(TopRightPt, BottomRightPt); } }
	
	public bool ContainPoint(Vector2 targetpoint)
	{
		Debug.LogError(string.Format("X {0} Width {1} Y {2} Height {3} ", X, Width, Y, Height));
		Debug.LogError(string.Format("targetPoint X {0} Y {1}", targetpoint.x, targetpoint.y));
		if((X <= targetpoint.x && targetpoint.x <= X + Width) && (Y <= targetpoint.y && targetpoint.y <= Y + Height))
		{
			return true;
		}
		else
			return false;
	}
	
	public bool InteractWithCircle(Vector2 point, int radius)
	{
		float distance = Vector2.Distance(new Vector2(X, Y), point);
		if(distance < radius + Width && distance < radius + Height)
			return true;
		else
			return false;
	}
	
	public override string ToString ()
	{
		return string.Format("X {0} Y {1} Width {2} Height {3}", X, Y, Width, Height);
	}
}